﻿using MailKit.Net.Smtp;
using MimeKit;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Runtime.InteropServices;

namespace 易发车网.Untils
{
    public class MyEmails
    {
        public string Account { get; set; }
        public string Pwd { get; set; }
        public string Host { get; set; }
        public int Port { get; set; }
        public bool SSL { get; set; }
    }

    public static class HaiMail
    {
        private static int i = 0;
        private static List<MyEmails> MyEmails = new List<MyEmails>();

        public static void Read()
        {
            if (File.Exists("emails.json"))
            {
                try
                {
                    MyEmails = JsonConvert.DeserializeObject<List<MyEmails>>(File.ReadAllText("emails.json"));
                }
                catch
                {

                }
            }
        }

        public static void SendMail(List<string> addresses, string subject, string content,int port)
        {
            var client = new System.Net.Mail.SmtpClient("smtp.gmail.com", port);
            client.EnableSsl = true;
            client.Credentials = new NetworkCredential("info@neighbourcar.page", "bpxmtxqavacgitpm");

            MailMessage mail = new MailMessage();
            mail.From = new MailAddress("info@neighbourcar.page");
            foreach (var address in addresses)
            {
                mail.To.Add(new MailAddress(address));
            }

            mail.Subject = subject;
            mail.Body = content;
            mail.IsBodyHtml = true;

            client.Send(mail);
        }  
    }
}
